package com.ht.serviceimpl;

import java.util.List;


import com.ht.dao.HistoryDao;
import com.ht.model.History;
import com.ht.service.HistoryService;
import com.ht.util.Constants;
import com.ht.util.MyPage;

public class HistoryServiceImpl implements HistoryService {

	HistoryDao historyDao ;
	
	public HistoryDao getHistoryDao() {
		return historyDao;
	}

	public void setHistoryDao(HistoryDao historyDao) {
		this.historyDao = historyDao;
	}

	public int addHistory(History  history ){
		int result =0  ;
		History sa = historyDao.getHistoryById(history);
		if (sa == null) {
		    result = historyDao.insertHistory(history);
		} else {
			result = 2;
		}
		return result;
	}
		
	public int deleteHistory(History  history) {
		return historyDao.deleteHistory(history);
	}

	public int updateHistory(History  history) {
		return historyDao.updateHistory(history);
	}
	public History getHistoryById(History  history) {
		return historyDao.getHistoryById(history);
	}
		
	public MyPage selectByCon(History history, int curPage){
		MyPage page = new MyPage();
		List result = historyDao.selectByCon(history,curPage,Constants.PAGE_SIZE) ;
		int recordCount = historyDao.getRecordCount(history);
		int totalPage = (recordCount%Constants.PAGE_SIZE==0)?recordCount/Constants.PAGE_SIZE:recordCount/Constants.PAGE_SIZE+1;
		page.setResult(result);
		page.setCurPage(curPage);
		page.setRecordCount(recordCount);
		page.setTotalPage(totalPage);
		return page ;
	  }
	
		
		

}
